<template>
  <form class="form-horizontal col-sm-offset-3 col-md-offset-3">
    <div>
      <div class="col-lg-11 text-center text-info">
        <h2>请登录</h2>
      </div>
      <div class="col-lg-10">
        <input type="text" class="form-control" v-model="user.username" name="username" placeholder="请输入账户名" required autofocus/>
      </div>
      <div class="col-lg-10"></div>
      <div class="col-lg-10">
        <input type="password" class="form-control" v-model="user.password" name="password" placeholder="请输入密码" required autofocus/>
      </div>
      <div class="col-lg-10">
        <button type="button"  v-on:click="login" class="btn btn-success col-lg-12">登录</button>
      </div>
    </div>
  </form>

</template>
<script>
  import {isEmpty} from '../../assets/js/util/stringUtil'
  export default {
    name: 'login',
    data() {
      return {
        user: {
          username: '',
          password: ''
        }
      }

    },
    methods: {
      login() {

        this.$http.options.emulateJSON = true;

        if(!(this.user.username || this.user.password)){
          alert("请输入用户名密码！");
          return;
        }
        //发送请求到服务器
        this.$http.post("http://106.75.8.121:8081/api/auth/jwt/token",this.user).then((response)=>{

          //存入token


          //alert(response.data.token);
          this.$router.push('/')
        },(response)=>{
         // alert("失败了");
          this.$router.push('/')
        }).catch(function (err) {
          this.$router.push('/')
        });




      }
    }

  }
</script>
